<!--
 *Author：jxx
 *Date：{Date}
 *Contact：283591387@qq.com
 *业务请在@/extension/sys/system/Sys_Role.jsx或Sys_Role.vue文件编写
 *新版本支持vue或【表.jsx]文件编写业务,文档见:https://v3.volcore.xyz/docs/view-grid、https://v3.volcore.xyz/docs/web
 -->
<template>
    <view-grid ref="grid" :columns="columns" :detail="detail" :details="details" :editFormFields="editFormFields"
        :editFormOptions="editFormOptions" :searchFormFields="searchFormFields" :searchFormOptions="searchFormOptions"
        :table="table" :extend="extend" :onInit="onInit" :onInited="onInited" :searchBefore="searchBefore"
        :searchAfter="searchAfter" :addBefore="addBefore" :updateBefore="updateBefore" :rowClick="rowClick"
        :modelOpenBefore="modelOpenBefore" :modelOpenAfter="modelOpenAfter" :loadTreeChildren="loadTreeChildren"
        :addAfter="addAfter" :updateAfter="updateAfter" :delAfter="delAfter">
        <!-- 自定义组件数据槽扩展，更多数据槽slot见文档 -->
        <template #gridHeader>
        </template>
    </view-grid>
</template>
<script setup lang="jsx">
import extend from "@/extension/sys/system/Sys_Role.jsx";
import viewOptions from './Sys_Role/options.js'
import { ref, reactive, getCurrentInstance, watch, onMounted } from "vue";
const grid = ref(null);
const { proxy } = getCurrentInstance()
//http请求，proxy.http.post/get
const { table, editFormFields, editFormOptions, searchFormFields, searchFormOptions, columns, detail, details } = reactive(viewOptions())

let gridRef;//对应[表.jsx]文件中this.使用方式一样
//生成对象属性初始化
const onInit = async ($vm) => {
    gridRef = $vm;
    gridRef.boxOptions.width = 500;
    //与jsx中的this.xx使用一样，只需将this.xx改为gridRef.xx
    //更多属性见：https://v3.volcore.xyz/docs/view-grid

    gridRef.rowKey = 'Role_Id';
    gridRef.columns.find((x) => {
        return x.field == 'ParentId';
    })?.hidden
}
//生成对象属性初始化后,操作明细表配置用到
const onInited = async () => {
    editFormOptions.forEach((x) => {
        x.forEach((item) => {
            if (item.field == 'ParentId') {
                item.title = '上级角色';
                //设置任意节点都能选中(默认只能选中最后一个节点)
                item.changeOnSelect = true;
            }
        });
    });
}
const loadTreeChildren = (tree, treeNode, resolve) => {
    //加载子节点
    let url = `api/role/getTreeTableChildrenData?roleId=${tree.Role_Id}`;
    proxy.http.post(url, {}).then((result) => {
        resolve(result.rows);
    });
}
const searchBefore = async (param) => {
    //判断加载根节点或子节点
    //没有查询条件，默认查询返回所有根节点数据
    if (!param.wheres.length) {
        param.value = 1;
    }
    return true;
    return true;
}
const searchAfter = async (rows, result) => {
    return true;
}
const addBefore = async (formData) => {
    //新建保存前formData为对象，包括明细表，可以给给表单设置值，自己输出看formData的值
    return true;
}
const updateBefore = async (formData) => {
    //编辑保存前formData为对象，包括明细表、删除行的Id
    return true;
}

const addAfter = () => {
    gridRef.initDicKeys();
    return true;
}
const updateAfter = () => {
    gridRef.initDicKeys();
    return true;
}
const delAfter = () => {
    gridRef.initDicKeys();
    return true;
}
const rowClick = ({ row, column, event }) => {
    //查询界面点击行事件
    // grid.value.toggleRowSelection(row); //单击行时选中当前行;
}
const modelOpenBefore = async (row) => {//弹出框打开后方法
    return true;//返回false，不会打开弹出框
}
const modelOpenAfter = (row) => {
    //弹出框打开后方法,设置表单默认值,按钮操作等
}
//监听表单输入，做实时计算
//watch(() => editFormFields.字段,(newValue, oldValue) => {	})
//对外暴露数据
defineExpose({})
</script>
<style lang="less" scope></style>
